const models = require("../models/index.js");
const Manadger = models.Manadger;
const manadgerService = require("../services/manadger-service.js");

class ManadgeController {
  // ------ регистрация клиента ----
  async registrationClient(req, res) {
    try {
      const { email, emailClient, password } = req.body;
      const manadger = await Manadger.findOne({ where: { email } });
      if (!manadger) {
        throw new Error(`Менеджер с почтой ${email} не существует`);
      }

      const clientData = await manadgerService.registrationClient(
        manadger.id,
        emailClient,
        password
      );
      return res.json(clientData);
    } catch (error) {
      return res.status(400).json({ message: error.message });
    }
  }
}

module.exports = new ManadgeController();
